package com.example.controller;

import com.example.data.request.ReqStudentList;
import com.example.entity.Student;
import com.example.service.impl.StudentServiceImpl;
import com.example.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Author:yanghua
 * Date:2023/7/20 18:19
 */
@RestController
@Slf4j
@RequestMapping("student")
public class StudentController {
    @Resource
    private StudentServiceImpl studentService;
    @PostMapping("add")
    public R addStudent(@RequestBody Student student) {
        return studentService.addStudent(student);
    }
    @PostMapping("getList")
    public R getStudentList(@RequestBody ReqStudentList reqStudentList) {
        return studentService.getStudentList(reqStudentList);
    }
    @PutMapping("updateByNumId")
    public R updateById(@RequestBody Student student){
        return studentService.updateByNumId(student);
    }
    @DeleteMapping("deleteByNumId/{nid}")
    public R deleteById(@PathVariable String nid) {
        return studentService.deleteByNumId(nid);
    }

    @GetMapping("getUsernameAndPasswordByNid/{nid}")
    public R getUserByNid(@PathVariable String nid) {
        return studentService.getStudentUsernameAndPasswordByNid(nid);
    }
    @GetMapping("getStudentInfo")
    public R getStudentInfo(@RequestHeader(name = "Authorization") String token) {
        return studentService.getStudentInfo(token);
    }
}
